package com.kingyun.gpsinspection.purificationservice.services.iam.outerservice.manage;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.kingyun.gpsinspection.purificationservice.dao.mapper.iam.manage.MaterialsInventoryMapper;
import com.kingyun.gpsinspection.purificationservice.dao.mapper.iam.manage.MaterialsMapper;
import com.kingyun.gpsinspection.purificationservice.facade.model.iam.manage.Materials;
import com.kingyun.gpsinspection.purificationservice.facade.model.iam.manage.MaterialsInventory;
import com.kingyun.gpsinspection.purificationservice.facade.service.iam.manage.MaterialsInventoryService;
import com.kingyun.gpsinspection.purificationservice.facade.service.iam.manage.OutMaterialsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by yangsy on 2017/2/16.
 */
@Service
public class OutMaterialsServiceImpl implements OutMaterialsService {
    @Autowired
    private MaterialsMapper materialsMapper;
    @Autowired
    private MaterialsInventoryMapper materialsInventoryMapper;
    @Autowired
    private MaterialsInventoryService materialsInventoryService;
    @Override
    public JSONObject queryMaterials(Materials materials) {
        JSONObject jsonObject = new JSONObject();
        materials.setLimit( materials.getLimit() == null ? 10 : materials.getLimit() );
        materials.setOffset( materials.getOffset() == null ? 0 : materials.getOffset() );
        jsonObject.put("total",materialsMapper.queryCount(materials));
        jsonObject.put("rows", JSON.toJSON(materialsMapper.queryList(materials)));
        return jsonObject;
    }

    @Override
    public MaterialsInventory queryMaterialsInventory(MaterialsInventory materialsInventory) {
        return materialsInventoryService.selectByMaterialsIdAndOrgId(materialsInventory);
    }

    @Override
    public JSONObject queryMaterialsAllInfo(MaterialsInventory materialsInventory) {
        JSONObject jsonObject = new JSONObject();
        materialsInventory.setLimit( materialsInventory.getLimit() == null ? 10 : materialsInventory.getLimit() );
        materialsInventory.setOffset( materialsInventory.getOffset() == null ? 0 : materialsInventory.getOffset() );
        jsonObject.put("total",materialsInventoryMapper.queryCount(materialsInventory));
        jsonObject.put("rows", JSON.toJSON(materialsInventoryMapper.queryList(materialsInventory)));
        return jsonObject;
    }
}
